package org.vestbjergbyggecenter.Controller;

import org.vestbjergbyggecenter.Model.*;

public class ProductCtr {
		private static ProductCtr instance;
		private ProductRecords products;
		private CategoryRecords categories;
		
		private ProductCtr()
		{
			products = ProductRecords.getInstance();
			categories = CategoryRecords.getInstance();
		}
		
		public static ProductCtr getInstance()
	    {
	        if(instance == null)
	        {
	            instance = new ProductCtr();
	        }
	        return instance;
	    }
		
		public void createProduct(int newID, String newName, String category, double newOriginalPrice, 
				int newQuantity, String newLocation)
		{
			Product newProduct = new Product(newID, newName, categories.getCategoryByTitle(category), newOriginalPrice,
					newQuantity, newLocation);
			products.addProduct(newProduct);
		}
		
		public Product getProduct(int id)
		{
			Product product = products.getProduct(id);
			return product;
		}
		
		public void updateProduct(int id, String name, String category, double price,
				int quantity, String location)
		{
			products.updateProduct(id, name, categories.getCategoryByTitle(category), price, quantity, location);
		}
		
		public void deleteProduct(int id)
		{
			products.removeProduct(id);
		}
		
		public void printProduct(int id)
	    {
	        Product product = products.getProduct(id);
	        if (product != null)
	            product.print();
	    }
		
		public void printAllProducts()
	    {
	        products.print();
	    }	
}


